package com.wy.wait_and_notify;

/**
 * @author 美女
 * @date 2022/05/02 14:44
 **/
public class Demo2 {
    static Object lock1=new Object();
    static Object lock2=new Object();
    static Object lock3=new Object();
    static class MyThread extends Thread{
        @Override
        public void run() {
            synchronized (lock1){
                System.out.println("lock1成功枷锁");
            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
        synchronized (lock1){
            synchronized (lock2){
                synchronized (lock3){
                    MyThread t=new MyThread();
                    t.start();
                    //主线程持有三把锁
                    //wait内部释放只会释放lock3锁（因为lock3持有wait）
                    lock3.wait();
                }
            }
        }
    }
}
//此时lock1成功加锁这句话不会执行，同理lock2也不会，而 synchronized (lock3)时加锁代码内的话会执行
//说明lock3.wait()时是把lock3锁释放了